/**
 * 
 */
package com.byzk.p2p.admin.log.controller;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.jsoup.helper.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.byzk.p2p.admin.base.controller.AdminBaseController;
import com.byzk.p2p.admin.base.util.DateUtils;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.group.dto.Group;
import com.byzk.p2p.admin.log.dto.ThirdMsgRecord;
import com.byzk.p2p.admin.log.service.ThirdMsgRecordService;

/*** <p>Title:ThirdMsgRecordController </p>
* <p>Description: </p>
* <p>Company:xbd </p>
* @author:Administrator
* @date:2016年10月18日上午9:57:10 */
@Controller
@RequestMapping(value="/admin/system")
public class ThirdMsgRecordController extends AdminBaseController {
   
	@Autowired
	private ThirdMsgRecordService thirdMsgRecordService;
	/**
	 * 
	* <p>Description:第三方消息列表</p>
	* <p>Company:xbd </p>
	* @author:lilei
	* @date:2016年10月24日上午10:38:20
	 */
	@RequestMapping(value = "/queryList" ,method=RequestMethod.GET)
	public String listByTerm(Model model,
			@RequestParam(value = "phone", required = false) String phone,
			@RequestParam(value = "type",  required = false) String type,
			@RequestParam(value = "sendTimeFrom",required=false)String sendTimeFrom,
			@RequestParam(value = "sendTimeTo",required=false)String sendTimeTo,
			@RequestParam(value = "index", required = false, defaultValue = "1") int index,
			@RequestParam(value = "limit", required = false, defaultValue = "10") int limit) throws Exception {
		
		    Map<String,Object> reqParam = new HashMap<String,Object>();
		    if(!StringUtils.isBlank(phone)){
		    	reqParam.put("phone",phone);
		    	model.addAttribute("phone", phone);
		    }
		    if(!StringUtil.isBlank(type) && !"-1".equals(type)){
		    	reqParam.put("type",type);
		    	model.addAttribute("type", type);
		    }
			if (StringUtils.isNotBlank(sendTimeFrom)) {
				reqParam.put("sendTimeFrom",DateUtils.getRealDate(DateUtils.convert(sendTimeFrom, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
				model.addAttribute("sendTimeFrom", sendTimeFrom);
			}
			if (StringUtils.isNotBlank(sendTimeTo)) {
				reqParam.put("sendTimeTo", DateUtils.getFullDate(DateUtils.convert(sendTimeTo, DateUtils.YEAR_MOUTH_DAY_FORMAT)));
				model.addAttribute("sendTimeTo", sendTimeTo);
			}
			PageInfo<ThirdMsgRecord> pageInfo = thirdMsgRecordService.getRecordListByTerm(reqParam, index, limit);
			model.addAttribute("pageInfo", pageInfo);
			return ftl(Thread.currentThread().getStackTrace());
	}
}
